<?php
/**
 * 个人会员中心 会员登录与注销类
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.06.23
 * @since       Version 1.0
 * 
 */
class LoginAction extends Action
{
    //退出登录
    public function loginExit()
    {
        $_SESSION["_user_login_haowaijiao"] = "";
        setcookie('haowj_ustat',"",time() - 86400,'/','.haowj.com');
        $this->ajaxReturn('','成功！',1);
    }
    /*
     * 广告类型注册  只判断手机号码跟
     */
    public function adRegister()
    {
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0); 
        $data['mobile'] = $this->_post('mobile');
        $verify = $this->_post('verify');
        $data['email'] = $this->_post('mail');
        $data['trade_id'] = $this->_post('trade');
        $data['origin'] = $this->_post('origin');
        if($this->checkMobile($data['mobile'])) $this->ajaxReturn('','此电话号码已注册！',0);
        if(!$this->checkVerify($verify)) $this->ajaxReturn('','验证码错误！',0); 
        $data['channel'] = cookie('HAOWJINFOCHANNEL');
        if(empty($data['channel'])) $data['channel'] = 'haowj';
        
        if(empty($data['origin'])) $data['origin'] = cookie('HAOWJINFOORIGIN');
        if(empty($data['origin'])) $data['origin'] = '';
        $data['create_time'] = time();
        $data['password'] = substr($data['mobile'], 5,6);
        if(D('Weixin_verify')->data($data)->add()) $this->ajaxReturn('','注册成功！',1); 
        else $this->ajaxReturn('','注册失败！',0);  
    }
    //验证码
    Public function verify()
    {
        import('ORG.Util.Image');
        Image::buildImageVerify('6','1','png','100','29');
    }
    //检查手机号
    public function ajaxCheckMobile()
    {
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0); 
        $mobile = $this->_post('mobile');
        $result = $this->checkMobile($mobile);
        if($result) $this->ajaxReturn('','此电话号码已注册！',0); 
        $this->ajaxReturn('','成功！',1); 
    }
    public function checkMobile($mobile)
    {
        $result = D('User')->where("mobile='$mobile'")->getField('id');
        if($result) return true;
        $result = D('Weixin_verify')->where("mobile='$mobile'")->getField('id');
        if($result) return true;
        return false;
    } 
    //检查验证码
    public function ajaxCheckVerify()
    {
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0); 
        $verify = $this->_post('verify');
        $result = $this->checkVerify($verify);
        if($result) $this->ajaxReturn('','成功！',1); 
        else $this->ajaxReturn('','错误！',0); 
    }
    public function checkVerify($verify)
    {
        if($_SESSION['verify']!=md5($verify)) return false;
        else return true;
    }
       
}